home *** CD-ROM | disk | FTP | other *** search
/ Sprite 1984 - 1993 / Sprite 1984 - 1993.iso / src / cmds / lfscollectdata / collectdata.c < prev    next >
Encoding:
C/C++ Source or Header  |  1991-12-18  |  6.5 KB  |  275 lines

  1. /* 
  2.  * lfscollectdata.c --
  3.  *
  4.  *    The collectdata program - Collect the data from an LFS file system. 
  5.  *
  6.  * Copyright 1989 Regents of the University of California
  7.  * Permission to use, copy, modify, and distribute this
  8.  * software and its documentation for any purpose and without
  9.  * fee is hereby granted, provided that the above copyright
  10.  * notice appear in all copies.  The University of California
  11.  * makes no representations about the suitability of this
  12.  * software for any purpose.  It is provided "as is" without
  13.  * express or implied warranty.
  14.  */
  15.  
  16. #ifndef lint
  17. static char rcsid[] = "$Header: /user2/mendel/lfs/src/cmds/checkLfs/RCS/checkLfs.c,v 1.1 90/06/01 10:10:18 mendel Exp Locker: mendel $ SPRITE (Berkeley)";
  18. #endif /* not lint */
  19.  
  20. #include "lfslib.h"
  21. #include <sprite.h>
  22. #include <stdio.h>
  23. #include <sys/types.h>
  24. #include <option.h>
  25. #include <stdlib.h>
  26. #include <string.h>
  27. #include <sys/file.h>
  28. #include <alloca.h>
  29. #include <bstring.h>
  30. #include <unistd.h>
  31. #include <bit.h>
  32. #include <time.h>
  33. #include <sys/time.h>
  34.  
  35.  
  36. /*
  37.  * Arguments.
  38.  */
  39. int    blockSize = 512;    /* File system block size. */
  40. char    *deviceName;        /* Device to use. */
  41. Boolean    printzero = FALSE;        /* Print zero numbers. */
  42. char    *outFileName = "-";    /* Output file name. */
  43.  
  44. Option optionArray[] = {
  45.     {OPT_DOC, (char *) NULL,  (char *) NULL,
  46.     "Dump the statistic counters from an LFS file system.\n Synopsis: \"lfscollectdata [switches] deviceName\"\n Command-line switches are:"},
  47.     {OPT_TRUE, "printzero", (Address) &printzero, 
  48.     "Do output numbers that are zero."},
  49.     {OPT_TRUE, "o", (Address) &outFileName, 
  50.     "Path name of output file."},
  51. };
  52.  
  53. static void PrintData _ARGS_((Lfs *lfsPtr, FILE *outFile));
  54. static void ShowCheckpointHdr _ARGS_((Lfs *lfsPtr, FILE *outFile));
  55. static void ShowUsageArray _ARGS_((Lfs *lfsPtr, FILE *outFile));
  56. static void ShowStats _ARGS_((Lfs_Stats *statsPtr, FILE *outFile));
  57.  
  58. extern int gettimeofday _ARGS_((struct timeval *tp, struct timezone *tzp));
  59.  
  60.  
  61.  
  62. /*
  63.  *----------------------------------------------------------------------
  64.  *
  65.  * main --
  66.  *
  67.  *    Main routine of lfscollectdata - parse arguments and do the work.
  68.  *
  69.  * Results:
  70.  *    None.
  71.  *
  72.  * Side effects:
  73.  *    Exits.
  74.  *
  75.  *----------------------------------------------------------------------
  76.  */
  77.  
  78. int
  79. main(argc,argv)
  80.     int    argc;
  81.     char *argv[];
  82. {
  83.     Lfs        *lfsPtr;
  84.     FILE    *outFile;
  85.     int        err;
  86.  
  87.     argc = Opt_Parse(argc, argv, optionArray, Opt_Number(optionArray), 0);
  88.     if (argc != 2) { 
  89.          Opt_PrintUsage(argv[0], optionArray, Opt_Number(optionArray));
  90.      exit(1);
  91.     } else {
  92.     deviceName = argv[1];
  93.     }
  94.     if ((outFileName[0] == '-') && (outFileName[1] == 0)) {
  95.     outFile = stdout;
  96.     } else {
  97.     outFile = fopen(outFileName, "w");
  98.     if (outFile == (FILE *) NULL) {
  99.         perror("open");
  100.         exit(1);
  101.     }
  102.     }
  103.     lfsPtr = LfsLoadFileSystem(argv[0], deviceName, blockSize, 
  104.             LFS_SUPER_BLOCK_OFFSET,
  105.                 O_RDONLY);
  106.     if (lfsPtr == (Lfs *) NULL) {
  107.     exit(1);
  108.     }
  109.     PrintData(lfsPtr, outFile);
  110.     err = fflush(outFile);
  111.     if (err) { 
  112.     fprintf(stderr,"%s: Error writing to file.\n", argv[0]);
  113.     }
  114.     exit((err == 0) ? 0 : 1);
  115.     return 0;
  116. }
  117.  
  118. /*
  119.  *----------------------------------------------------------------------
  120.  *
  121.  * PrintData --
  122.  *
  123.  *    Print the interesting data from a file system.
  124.  *
  125.  * Results:
  126.  *    None.
  127.  *
  128.  * Side effects:
  129.  *    None.
  130.  *
  131.  *----------------------------------------------------------------------
  132.  */
  133.  
  134. static void
  135. PrintData(lfsPtr, outFile)
  136.     Lfs    *lfsPtr;
  137.     FILE *outFile;
  138. {
  139.     struct timeval tim;
  140.  
  141.     gettimeofday(&tim, (struct timezone *) NULL);
  142.     ShowCheckpointHdr(lfsPtr, outFile); 
  143.     ShowUsageArray(lfsPtr, outFile);
  144.     ShowStats(&lfsPtr->stats, outFile);
  145.     fprintf(outFile, "gettimeofday.tv_sec %u\n", tim.tv_sec);
  146.     fprintf(outFile, "gettimeofday.tv_usec %u\n", tim.tv_usec);
  147. }
  148.  
  149. /*
  150.  *----------------------------------------------------------------------
  151.  *
  152.  * ShowCheckpointHdr --
  153.  *
  154.  *    Output the contents of the current checkpoint header of a filesystem.
  155.  *
  156.  * Results:
  157.  *    None.
  158.  *
  159.  * Side effects:
  160.  *    None.
  161.  *
  162.  *----------------------------------------------------------------------
  163.  */
  164.  
  165.  
  166. static void
  167. ShowCheckpointHdr(lfsPtr, outFile)
  168.     Lfs    *lfsPtr;
  169.     FILE *outFile;
  170. {
  171.     LfsCheckPointHdr    *hdrPtr;
  172.  
  173.     hdrPtr = lfsPtr->checkPointHdrPtr;
  174.  
  175. #ifdef __STDC__
  176. #define    M(f)    if (printzero || hdrPtr-> f ) fprintf(outFile, "LfsCheckPointHdr." #f " %u\n", hdrPtr-> f )
  177. #else
  178. #define    M(f)    if (printzero || hdrPtr-> f ) fprintf(outFile, "LfsCheckPointHdr.f %u\n", hdrPtr-> f )
  179. #endif
  180.     M(timestamp);
  181.     M(version);
  182.     fprintf(outFile, "LfsCheckPointHdr.domainPrefix %s\n", hdrPtr->domainPrefix);
  183.     M(domainNumber);
  184.     M(attachSeconds);
  185.     M(detachSeconds);
  186.     M(serverID);
  187. #undef M
  188. }
  189.  
  190.  
  191. /*
  192.  *----------------------------------------------------------------------
  193.  *
  194.  * ShowUsageArray --
  195.  *
  196.  *    Output the contents of the segment usage array.
  197.  *
  198.  * Results:
  199.  *    None.
  200.  *
  201.  * Side effects:
  202.  *    None.
  203.  *
  204.  *----------------------------------------------------------------------
  205.  */
  206.  
  207. static void
  208. ShowUsageArray(lfsPtr, outFile)
  209.     Lfs    *lfsPtr;
  210.     FILE *outFile;
  211. {
  212.     LfsSegUsageParams    *usagePtr;
  213.     LfsSegUsageCheckPoint    *cp;
  214.     LfsSegUsageEntry        *entryPtr;
  215.     int    i;
  216.  
  217.     usagePtr = &(lfsPtr->superBlock.usageArray);
  218.     cp = &lfsPtr->usageArray.checkPoint;
  219.  
  220. #ifdef __STDC__
  221. #define    M(f)    if (printzero || cp-> f ) fprintf(outFile, "LfsSegUsageCheckPoint." #f " %u\n", cp-> f )
  222. #else
  223. #define    M(f)    if (printzero || cp-> f ) fprintf(outFile, "LfsSegUsageCheckPoint.f %u\n", cp-> f )
  224. #endif
  225.     M(freeBlocks);
  226.     M(numClean);
  227.     M(numDirty);
  228.     M(dirtyActiveBytes);
  229.     M(currentSegment);
  230.     M(currentBlockOffset);
  231.     M(curSegActiveBytes);
  232.     M(previousSegment);
  233.     M(cleanSegList);
  234. #undef M
  235.     for (i = 0; i < usagePtr->numberSegments; i++) {
  236.     entryPtr = LfsGetUsageArrayEntry(lfsPtr, i);
  237.     fprintf(outFile, 
  238.        "LfsSegUsageEntry.Seg %d activeBytes %d lastWrite %u flags %u\n", 
  239.         i, entryPtr->activeBytes, entryPtr->timeOfLastWrite, 
  240.         entryPtr->flags);
  241.     }
  242. }
  243.  
  244.  
  245. /*
  246.  *----------------------------------------------------------------------
  247.  *
  248.  * ShowStats --
  249.  *
  250.  *    Output the stats structure of the file system..
  251.  *
  252.  * Results:
  253.  *    None.
  254.  *
  255.  * Side effects:
  256.  *    None.
  257.  *
  258.  *----------------------------------------------------------------------
  259.  */
  260.  
  261. static void 
  262. ShowStats(statsPtr, outFile)
  263.     Lfs_Stats *statsPtr;
  264.     FILE *outFile;
  265. {
  266.     int    i;
  267. #include "statprint.h"
  268.     for (i = 0; i < LFS_STATS_CDIST_BUCKETS; i++) {
  269.     if (printzero || statsPtr->cleaningDist[i]) 
  270.         fprintf(outFile,"Lfs_Stats.cleaningDist %d %u\n",i, 
  271.             statsPtr->cleaningDist[i]);
  272.     }
  273. }
  274.  
  275.